<?php

namespace app\api\controller\xiluhouse;

use app\common\controller\Api;
use app\common\model\xiluhouse\HouseTrends as HouseTrendsModel;
use think\Db;

/**
 * @title   房源动态类
 * @desc    获取房源动态相关的接口
 */
class Housetrends extends Api
{
    // 无需登录的接口,*表示全部
    protected $noNeedLogin = ['house_trends_list', 'house_trends_detail'];
    // 无需鉴权的接口,*表示全部
    protected $noNeedRight = '*';


    /**
     * @title  楼盘动态列表
     * @desc  获取 楼盘动态列表
     *
     * @param int    $house_id       0      关联房源id（如果不传则按时间倒序排）
     * @param string    $city       上海市   城市
     *
     */
    public function house_trends_list()
    {
        $house_id = $this->request->param('house_id/d', 0);
        $model = new HouseTrendsModel();
        $map = [];
        if ($house_id) {
            $map['house_id'] = $house_id;
        }
        $city = $this->request->param('city/s', '上海市');
        $map['house.city'] = ['like', $city . '%'];
        $map['house.status'] = 'normal';
        // show_date 倒序
        // $data=$model->getListByMap($map,['house'],['show_date'=>'desc','weigh'=>'desc','id'=>'desc']);
        $list = $model->with(['house'])->where($map)->where('house.deletetime', null)->order(['show_date' => 'desc', 'weigh' => 'desc', 'id' => 'desc'])->paginate();
        $this->success('', $list);
    }

    /**
     * @title  楼盘动态详情
     * @desc  获取 楼盘动态详情
     *
     * @param int    $id       0      动态id
     *
     */
    public function house_trends_detail()
    {
        $id = $this->request->param('id/d', 0);
        if (!$id) {
            $this->error('参数错误');
        }
        $model = new HouseTrendsModel();
        // $info=$model->getInfoByMap(['id'=>$id],['house']);
        $info = $model->with(['house'])->find($id);
        if (empty($info)) {
            $this->error('不存在动态');
        }
        $this->success('', $info);
    }
}
